home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Science / µSim 1.0b5 folder / source / AEHandlers.c next >
Encoding:
Text File  |  1994-07-07  |  5.4 KB  |  195 lines  |  [TEXT/MMCC]

  1. /*
  2. Copyright © 1993,1994 by Fabrizio Oddone
  3. ••• ••• ••• ••• ••• ••• ••• ••• ••• •••
  4. This source code is distributed as freeware: you can copy, exchange, modify this
  5. code as you wish. You may include this code in any kind of application: freeware,
  6. shareware, or commercial, provided that full credits are given.
  7. You may not sell or distribute this code for profit.
  8. */
  9.  
  10. //#pragma load "MacDump"
  11.  
  12. #include    "AEHandlers.h"
  13. #include    "Assembler.h"
  14. #include    "ControlStore.h"
  15. #include    "DoMenu.h"
  16. #include    "Globals.h"
  17. #include    "Main.h"
  18. #include    "myMemory.h"
  19. #include    "SimUtils.h"
  20.  
  21. //#pragma segment Main
  22.  
  23. static OSErr myGotRequiredParams(const AppleEvent *theAppleEvent);
  24.  
  25.  
  26. pascal OSErr myHandleOAPP(const AppleEvent *theAppleEvent, AppleEvent */*reply*/,
  27.                     long /*handlerRefcon*/)
  28. {
  29. //#pragma unused (reply, handlerRefcon)
  30.  
  31. AEIdleUPP    myIdleFunctUPP = NewAEIdleProc(myIdleFunct);
  32. register OSErr    err;
  33.  
  34. if ((err = myGotRequiredParams(theAppleEvent)) == noErr)
  35.     if ((err = AESetInteractionAllowed(kAEInteractWithAll)) == noErr)
  36.         if ((err = AEInteractWithUser(kNoTimeOut, 0L, myIdleFunctUPP)) == noErr)
  37.             if (DocIsOpen == false) {
  38.                 DoNew();
  39.                 UnloadSeg(DoNew);
  40.                 DoMenuWindows(kMItem_Microprogram);
  41.                 }
  42. if (myIdleFunctUPP)
  43.     DisposeRoutineDescriptor(myIdleFunctUPP);
  44. return err;
  45. }
  46.  
  47. pascal OSErr myHandleODOC(const AppleEvent *theAppleEvent, AppleEvent */*reply*/,
  48.                     long /*handlerRefcon*/)
  49. {
  50. //#pragma unused (reply, handlerRefcon)
  51.  
  52. AEIdleUPP    myIdleFunctUPP = NewAEIdleProc(myIdleFunct);
  53. FSSpec    myFSS;
  54. FInfo    myInfo;
  55. AEDescList    docList;
  56. AEKeyword    keywd;
  57. DescType    returnedType;
  58. Size    actualSize;
  59. long    itemsInList;
  60. register long    i;
  61. register OSErr    err;
  62.  
  63. if (noErr == (err = AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, &docList))) {
  64.     if ((err = myGotRequiredParams(theAppleEvent)) == noErr)
  65.         if ((err = AESetInteractionAllowed(kAEInteractWithAll)) == noErr)
  66.             if ((err = AEInteractWithUser(kNoTimeOut, 0L, myIdleFunctUPP)) == noErr)
  67.                 if ((err = AECountItems(&docList, &itemsInList)) == noErr)
  68.                     for (i = 1; i <= itemsInList; i++) {
  69.                         if ((err = AEGetNthPtr(&docList, i, typeFSS, &keywd, &returnedType,
  70.                                                 (Ptr)&myFSS, sizeof(myFSS), &actualSize)) == noErr) {
  71.                             if ((err = FSpGetFInfo(&myFSS, &myInfo)) == noErr) {
  72.                                 switch (myInfo.fdType) {
  73. /* we should get the script code from the Apple Event; how??? */
  74. #ifndef __SCRIPT__
  75. #define    smSystemScript    -1
  76. #endif
  77.                                     case kFTY_CSTORE    :    
  78.                                         if (ReadyToTerminate()) {
  79.                                             err = myOpenCSFile(&myFSS, smSystemScript,
  80.                                                                 (myInfo.fdFlags & kfIsStationery) != 0);
  81.                                             UnloadSeg(myOpenCSFile);
  82.                                             }
  83.                                         break;
  84.                                     case kFTY_RAM    :    err = myOpenFile(&myFSS, gMMemory, kSIZE_RAM);
  85.                                                         UnloadSeg(myOpenFile);
  86.                                         break;
  87.                                     case kFTY_REG    :    err = OpenProcessorState(&myFSS);
  88.                                                         UnloadSeg(OpenProcessorState);
  89.                                         break;
  90.                                     case 'TEXT'    :    err = myAsmFile(&myFSS);
  91.                                                     UnloadSeg(myAsmFile);
  92.                                         break;
  93.                                     default :    err = paramErr;
  94.                                     }
  95.                                 }
  96.                             }
  97.                         }
  98.     (void)AEDisposeDesc(&docList);
  99.     }
  100. if (myIdleFunctUPP)
  101.     DisposeRoutineDescriptor(myIdleFunctUPP);
  102. return err;
  103. }
  104.  
  105. pascal OSErr myHandlePDOC(const AppleEvent */*theAppleEvent*/, AppleEvent */*reply*/,
  106.                     long /*handlerRefcon*/)
  107. {
  108. //#pragma unused (theAppleEvent, reply, handlerRefcon)
  109.  
  110. return errAEEventNotHandled;
  111. }
  112.  
  113. pascal OSErr myHandleQUIT(const AppleEvent *theAppleEvent, AppleEvent */*reply*/,
  114.                     long /*handlerRefcon*/)
  115. {
  116. //#pragma unused (reply, handlerRefcon)
  117.  
  118. register OSErr    err;
  119.  
  120. err = myGotRequiredParams(theAppleEvent);
  121. return(err ? err : (ReadyToTerminate() ? (gDoneFlag = true, noErr) : userCanceledErr));
  122. }
  123.  
  124. static OSErr myGotRequiredParams(const AppleEvent *theAppleEvent)
  125. {
  126. DescType    returnedType;
  127. Size    actualSize;
  128. register OSErr    err;
  129.  
  130. err = AEGetAttributePtr(theAppleEvent, keyMissedKeywordAttr, typeWildCard,
  131.                         &returnedType, 0L, 0, &actualSize);
  132. return(err ? (err == errAEDescNotFound ? noErr : err) : errAEEventNotHandled);
  133. }
  134.  
  135. pascal Boolean myIdleFunct(EventRecord *event, long *sleepTime, RgnHandle *mouseRg)
  136. {
  137. switch (event->what) {
  138.     case nullEvent:
  139.         *mouseRg = (RgnHandle)nil;
  140.         *sleepTime = 0x7FFFFFFF;
  141.         break;
  142.     case updateEvt:
  143.         DoUpdate(event);
  144.         break;
  145.     case activateEvt:
  146.         DoActivate(event);
  147.         break;
  148.     case osEvt:
  149.         DoOSEvent(event);
  150.         break;
  151.     }
  152. return false;
  153. }
  154.  
  155. pascal OSErr myHandleIO(const AppleEvent *theAppleEvent, AppleEvent */*reply*/,
  156.                     long /*handlerRefcon*/)
  157. {
  158. //#pragma unused (reply, handlerRefcon)
  159.  
  160. AEIdleUPP    myIdleFunctUPP = NewAEIdleProc(myIdleFunct);
  161. register OSErr    err;
  162.  
  163. if ((err = myGotRequiredParams(theAppleEvent)) == noErr)
  164.     if ((err = AESetInteractionAllowed(kAEInteractWithSelf)) == noErr)
  165.         if ((err = AEInteractWithUser(kNoTimeOut, 0L, myIdleFunctUPP)) == noErr) {
  166.             gInTheForeground = true;
  167.             InitCursor();
  168. //            PostEvent(keyDown, 3);
  169.             DoMenuWindows(kMItem_IO);
  170.             }
  171. if (myIdleFunctUPP)
  172.     DisposeRoutineDescriptor(myIdleFunctUPP);
  173. return err;
  174. }
  175.  
  176. pascal OSErr myHandleGenericAlert(const AppleEvent *theAppleEvent, AppleEvent */*reply*/,
  177.                             long /*handlerRefcon*/)
  178. {
  179. //#pragma unused (reply, handlerRefcon)
  180.  
  181. AEIdleUPP    myIdleFunctUPP = NewAEIdleProc(myIdleFunct);
  182. register OSErr    err;
  183.  
  184. if ((err = myGotRequiredParams(theAppleEvent)) == noErr)
  185.     if ((err = AESetInteractionAllowed(kAEInteractWithSelf)) == noErr)
  186.         if ((err = AEInteractWithUser(kNoTimeOut, 0L, myIdleFunctUPP)) == noErr) {
  187.             gInTheForeground = true;
  188.             InitCursor();
  189.             }
  190. if (myIdleFunctUPP)
  191.     DisposeRoutineDescriptor(myIdleFunctUPP);
  192. return err;
  193. }
  194.  
  195.